package com.example.myapplication.found.model;

import com.example.myapplication.found.bean.StockBean;
import com.example.myapplication.found.bean.StockKlineBean;
import com.example.myapplication.found.contract.FenxiCallback;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import static java.util.Map.Entry.comparingByKey;
import static java.util.stream.Collectors.toMap;

/**
 * @author: rongfeng
 * @date: 2022/2/25
 * @description 天地板
 */
public class Fenxi6 extends BaseData {


    public Fenxi6(StockBean stockBean, StockBean weekStockBean) {
        super(stockBean, weekStockBean);
    }

    @Override
    public void start() {
        test1();
    }

    public static String startDate;
    public static String endDate;
    public static int maxSize;
    public static int lineTotal;
    public static int stockTotal;
    public static int countTotal;

    static List<String> codeList = new ArrayList<>();
    static List<StockKlineBean> reList = new ArrayList<>();

    private void test1() {
        if (!codeList.contains(fundCode)) {
            codeList.add(fundCode);
        } else {
            if (callback != null) {
                callback.fenxiCallback(1);
            }
            return;
        }
        stockTotal++;
        if (stockBean.klineList.size() > maxSize) {
            maxSize = stockBean.klineList.size();
            startDate = stockBean.klineList.get(0).date;
            endDate = stockBean.klineList.get(maxSize - 1).date;
        }
        for (int i = 0; i < stockBean.klineList.size(); i++) {
            lineTotal++;
            if (i - 1 > 0) {
                StockKlineBean lastBean = stockBean.klineList.get(i - 1);
                StockKlineBean bean = stockBean.klineList.get(i);
                if ((bean.zuigao / (float) lastBean.shouPan) > 1.097f && (bean.zuidi / (float) lastBean.shouPan) <= 0.92f && bean.chg < -9) {
                    countTotal++;
                    System.out.println(bean.date + "  " + fundName);
                }
            }
        }
        if (callback != null) {
            callback.fenxiCallback(1);
        }
    }


    public static void analysis() {
        System.out.println("A股最近3年天地板次数统计");
        System.out.println("统计开始日期： " + Fenxi6.startDate + " 截止日期：" + endDate);
//        System.out.println("统计股票数量：" + Fenxi6.stockTotal + " 支");
        System.out.println("发生次数：" + Fenxi6.countTotal);
        System.out.println("发生概率：" + (Fenxi6.countTotal / (float) lineTotal) * 100 + "%");
        System.out.println();
    }


    public static double median(List<Float> total) {
        if (total.size() <= 0) {
            return 0;
        }
        double j = 0;
        //集合排序
        Collections.sort(total);
        int size = total.size();
        if (size % 2 == 1) {
            j = total.get((size - 1) / 2);
        } else {
            //加0.0是为了把int转成double类型，否则除以2会算错
            j = (total.get(size / 2 - 1) + total.get(size / 2) + 0.0) / 2;
        }
        return j;
    }

}
